/*
 * @Author: Qimu
 * @Date: 2020-04-15 17:56:50
 * @LastEditors: Qimu
 * @LastEditTime: 2020-04-22 03:06:33
 * @Description: file content
 * @FilePath: \koa2_api\module\db\mongodb.js
 */
const mongoose = require('mongoose');
const config = require('../config/config');//配置文件
// const url = `mongodb://${config.mongodb.user}@${config.mongodb.host}:${config.mongodb.port}/?authSource=${config.mongodb.user}`;
// const url = 'mongodb://admin@localhost:30000/?authSource=admin';
// const url = 'mongodb://admin:xyq520lsl@127:0:0:1:30000/koa?authSource=admin';
// const url = 'mongodb://admin:xyq520lsl@127.0.0.1:30000/koaApi';
// const url = `mongodb://${config.mongodb.user}:${config.mongodb.password}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.database}`;
const url = `mongodb://${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.database}`;
console.log(url);

// 创建连接对象
mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, (err) => {
  if (err) {
    console.log(err);
  } else {
    console.log('数据库连接成功');
  }
})

module.exports = mongoose;   